<template>
  <div class="container">
    <div class="top-box">
      <div class="left-box">
        <div class="color-box"></div>
        <p>公告发布</p>
      </div>
      <div class="right-box">
        <el-button type="info" icon="el-icon-back" class="btn_fanhui" @click="Return">返回</el-button>
      </div>
    </div>
    <div class="content-box">
      <div class="Title-box">公告发布</div>
      <div class="table-box">
        <div class="item-box">
          <div class="theme-box">主题</div>
          <div class="themee-box">
            <el-input class="title" v-model="title" placeholder="请输入主题"></el-input>
          </div>
        </div>
        <div class="item1-box">
          <div class="left1-box">
            <div class="theme1-box">部门</div>
            <div class="select-box">
              <el-cascader
                v-model="selectedOptions"
                style="width:60%"
                :options="options"
                :props="props"
                collapse-tags
                @change="handleItemChange"
              ></el-cascader>
            </div>
          </div>
          <div class="right1-box">
            <div class="theme2-box">接收人</div>
            <div class="select1-box">
              <el-cascader
                style="width:60%"
                :options="persons"
                v-model="selectedPersons"
                :props="props"
                collapse-tags
                clearable
                @change="handleItemChange1"
              ></el-cascader>
            </div>
          </div>
        </div>
        <div class="item1-box">
          <div class="left1-box">
            <div class="theme1-box">信息类型</div>
            <div class="select-box">
              <template>
                <el-select v-model="typeVal" style="width:60%">
                  <el-option
                    v-for="item in typeList"
                    :key="item.value"
                    :label="item.label"
                    :value="item.label"
                  ></el-option>
                </el-select>
              </template>
            </div>
          </div>
          <div class="right1-box">
            <div class="theme2-box">重要程度</div>
            <div class="select1-box">
              <el-select v-model="degreeVal" style="width:60%">
                <el-option
                  v-for="item in degreeList"
                  :key="item.value"
                  :label="item.label"
                  :value="item.label"
                ></el-option>
              </el-select>
            </div>
          </div>
        </div>
        <!-- <div class="item1-box">
          <div class="left1-box">
            <div class="theme1-box">主题</div>
            <div class="select-box">
               <el-input style="width:60%" v-model="title" placeholder="请输入主题"></el-input>
            </div>
          </div>
          <div class="right1-box">
            <div class="theme2-box">接收人</div>
            <div class="select1-box">
              <el-cascader
                style="width:60%;"
                :options="options"
                :props="{ multiple: true, checkStrictly: true }"
                clearable
              ></el-cascader>
            </div>
          </div>
        </div>-->
        <div class="details-box">
          <div class="theme3-box">详情</div>
          <div class="select3-box">
            <el-input
              type="textarea"
              :autosize="{ minRows: 4, maxRows: 6}"
              placeholder="请输入内容"
              v-model="main"
            ></el-input>
          </div>
        </div>
      </div>
      <div class="btn-box">
        <el-button type="primary" @click="addnotice()">确定</el-button>
        <el-button type="info" @click="Return">返回</el-button>
      </div>
    </div>
  </div>
</template>
<script>
import axios from "axios";
export default {
  data () {
    return {
      props: { multiple: true },
      selectedOptions: [],
      departList: [],//部门后台
      options: [],
      persons: [],
      selectedPersons: [],
      personList: [],//接收人后台
      main: "",
      title: "",
      degreeList: [{ value: 1, label: "一般" }, { value: 2, label: "重要" }, { value: 3, label: "非常" }],
      degreeVal: "",
      typeList: [{ value: 1, label: "类型1" }, { value: 2, label: "类型2" }, { value: 3, label: "类型3" }],
      typeVal: "",
      creater: 0,
      Mark: 0,
    };
  },
  created () {
    this.getDeparts();
    this.creater = JSON.parse(localStorage.getItem("message")).Id;
  },
  methods: {
    Return () {
      window.history.go(-1);
    },
    //获取部门
    getDeparts () {
      var obj = { id: 4 };
      var objs = JSON.stringify(obj);
      axios("/apis/AdministrationManage.asmx/GetData?index=1&jsondata=" + objs).then(({ data }) => {
        var datas = this.$x2js.xml2js(data);
        var list = JSON.parse(datas.string.__text);
        this.options = list;
      });
    },
    //获取接收部门集合
    handleItemChange () {
      this.departList = [];
      for (var i = 0; i < this.selectedOptions.length; i++) {
        this.departList.push(this.selectedOptions[i][1]);
      }
      var objs = JSON.stringify(this.departList);
      let the = { index: 2, jsondata: objs };
      axios.post("/apis/AdministrationManage.asmx/GetData", the).then(({ data }) => {
        var list = eval('(' + data.d + ')');
        this.persons = list;
      });
    },
    //获取接收人集合
    handleItemChange1 () {
      this.personList = [];
      for (var i = 0; i < this.selectedPersons.length; i++) {
        this.personList.push(this.selectedPersons[i][1]);
      }
    },
    addnotice () {
      if (this.Mark == 0) {
        if (this.title == "") { this.$message.error("主题非空"); return; };
        if (this.typeVal == "") { this.$message.error("请选择类型"); return; };
        if (this.degreeVal == "") { this.$message.error("请选择重要程度"); return; };
        if (this.main == "") { this.$message.error("内容非空"); return; };
        if (this.departList.length <= 0) { this.$message.error("请选择接收部门"); return; };
        if (this.personList.length <= 0) { this.$message.error("请选择接收人"); return; };
        var obj = {
          basemess: { creater: this.creater, title: this.title, type: this.typeVal, degree: this.degreeVal, main: this.main },
          depart: this.departList,
          receiver: this.personList,

        };
        var objs = JSON.stringify(obj); let the = { index: 1, jsondata: objs };
        this.Mark = 1;
        axios.post("/apis/AdministrationManage.asmx/Add", the).then(({ data }) => {
          var list = JSON.parse(data.d);
          if (list.flag == true) {
            this.$message.success(list.tip);
            setTimeout(() => {
              window.history.go(-1);
            }, 500);          }
          else { this.$message.error(list.tip); }
        });
      }
    }
  }
};
</script>
<style lang="scss" scoped>
@import '@/assets/scss/base.scss';
.top-box {
  width: 100%;
  height: 60px;
  overflow: hidden;
  // border: 1px solid $red;
}
.left-box {
  width: 100px;
  height: 40px;
  float: left;
  margin-top: 10px;
  overflow: hidden;
  margin-left: 1%;
  // border: 1px solid red;
}
.color-box {
  width: 5px;
  height: 20px;
  float: left;
  margin-top: 10px;
  background-color: $Header_color;
}
.left-box p {
  float: left;
  margin-left: 5px;
  line-height: 40px;
}
.right-box {
  float: right;
  width: 90px;
  height: 40px;
  margin-right: 2%;
  border-radius: 8px;
  margin-top: 10px;
  background-color: $return-color;
  // border: 1px solid red;
}
.right-box:hover {
  background-color: #a4a6ad;
}
.right-box span {
  float: left;
  color: $white;
  font-size: $font-size-medium;
  line-height: 40px;
  //  border: 1px solid red;
}
.right-box img {
  width: 30px;
  height: 30px;
  margin-top: 5px;
  margin-left: 6px;
  float: left;
  // border: 1px solid red;
}
.content-box {
  width: 98%;
  height: 600px;
  margin: 0 auto;
  border-radius: 2px;
  background-color: $white;
}
.Title-box {
  width: 100%;
  height: 110px;
  line-height: 110px;
  text-align: center;
  font-size: $font-size-large;
  font-weight: bold;
  letter-spacing: 5px;
  // border: 1px solid red;
}
.title {
  width: 50%;
}
.table-box {
  width: 80%;
  margin: 0 auto;
  border: 1px solid $bordercolor;
}
.item-box {
  width: 100%;
  height: 60px;
  display: flex;
  border-bottom: 1px solid $bordercolor;
}
.theme-box {
  width: 10%;
  height: 60px;
  line-height: 60px;
  text-align: center;
  font-weight: bold;
  font-size: $font-size-medium;
  border-right: 1px solid $bordercolor;
}
.themee-box {
  flex: 1;
  height: 60px;
  line-height: 60px;
  text-align: center;
  font-weight: bold;
  font-size: $font-size-medium;
}
.themee-box input {
  width: 100%;
  height: 59px;
  outline: none;
  text-align: center;
  border: none;
}
.oneitem-box {
  width: 100%;
  height: 60px;
  overflow: hidden;
  float: left;
  border-bottom: 1px solid $bordercolor;
}
.item1-box {
  width: 100%;
  height: 60px;
  overflow: hidden;
  border-bottom: 1px solid $bordercolor;
}
.left1-box {
  width: 50%;
  height: 60px;
  float: left;
  overflow: hidden;
}
.theme1-box {
  width: 20%;
  height: 60px;
  float: left;
  line-height: 60px;
  text-align: center;
  font-weight: bold;
  font-size: $font-size-medium;
  border-right: 1px solid $bordercolor;
}
.select-box {
  width: 79%;
  height: 60px;
  float: left;
  line-height: 60px;
  text-align: center;
  border-right: 1px solid $bordercolor;
}
// .select-box .el-select {
//   margin-left: 10%;
// }
.right1-box {
  width: 50%;
  height: 60px;
  float: left;
  overflow: hidden;
}
.theme2-box {
  width: 20%;
  height: 60px;
  float: left;
  line-height: 60px;
  text-align: center;
  font-weight: bold;
  font-size: $font-size-medium;
  border-right: 1px solid $bordercolor;
}
.select1-box {
  width: 79%;
  height: 60px;
  float: left;
  line-height: 60px;
  text-align: left;
  text-align: center;
}
// .select1-box .el-select {
//   margin-left: 10%;
// }
.details-box {
  display: flex;
  width: 100%;
  align-items: center;
}
.theme3-box {
  width: 10%;
  text-align: center;
  font-weight: bold;
  font-size: $font-size-medium;
}
.select3-box {
  border-left: 1px solid $bordercolor;
  flex: 1;
  text-align: center;
}
.select3-box .el-textarea {
  width: 90%;
  margin: 10px auto;
}
.btn-box {
  width: 20%;
  height: 60px;
  margin: 0 auto;
  margin-top: 20px;
  padding-left: 100px;
  // border: 1px solid red;
}
</style>